import { getChannel } from '../../../services/basicCenter';

export default {

    namespace: 'channelManage',

    state: {
      data:[],
      page:{},
      totalAmount:0
    },

    subscriptions: {
        setup ({ dispatch, history }) {
          history.listen((location) => {
            if (location.pathname === '/basicCenter/channelManage') {
              dispatch({
                type: 'getChannel',
                payload:{
                  // start:1,
                  // length:10
                }
              })
            }
          })  
          
        }
    },
    effects : {
      *getChannel ({ payload }, { call, put }) {
        const channelData = yield call(getChannel, payload);
        const {data,page,totalAmount}=channelData
        yield put({
          type: 'save',
          payload:{
            data,
            page,
            totalAmount
          }
        })
      },
    },
    reducers : {
      save (state, action) {
        return {
          ...state,
          ...action.payload
        }
      },
    }

}
